package com.huajx.tuopuda.client.udp.codec.auth;

import com.huajx.tuopuda.client.udp.TuopudaDirect;
import com.huajx.tuopuda.client.udp.TuopudaUtil;
import com.huajx.tuopuda.client.udp.codec.AbstractCodec;

/**
 * 删除权限
 * <p>
 * 9.2.3.8.5删除一个权限[1108] (此指令只适合1000个权限内的操作)
 *
 * @author: lisa 叶新华
 * @create: 2019-09-28 18:00
 */
public class RemoveAuthCodec extends AbstractCodec {
    private final static int function = TuopudaDirect.D_1108;
    private int cardId;

    public RemoveAuthCodec(int sn) {
        setSn(sn);
    }

    public RemoveAuthCodec(int sn, int cardId) {
        this(sn);
        this.cardId = cardId;
    }

    public static RemoveAuthCodec getInstance(int sn, int cardId) {
        return new RemoveAuthCodec(sn, cardId);
    }

    @Override
    public byte[] encode() {
        if (cardId <= 0) {
            return new byte[0];
        }
        return encode(getSn(), function, (bytes) -> TuopudaUtil.replaceBytes(bytes, cardId, 7, 4));
    }

    public int getCardId() {
        return cardId;
    }

    public void setCardId(int cardId) {
        this.cardId = cardId;
    }
}
